package com.core.dao;

import com.core.domain.DTO.LygStadiumDTO;
import com.core.domain.Stadium;
import com.core.domain.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @author 刘玉贵
 * @version 666
 */
@Repository
public interface LygDao {
    @Select("select * from stadium where isDelete = 0")
    List<LygStadiumDTO> selectAllStadium();

    @Select("select count(*) from usestadium where DATE(reservationEndTime) >= CURRENT_DATE() and TIME(reservationEndTime) > CURRENT_TIME() and isDelete = 0 and teamId = #{id}")
    int countById(int id);

    @Insert("insert into usestadium(userId,teamId,reservationStartTime,reservationEndTime,reservedNumber) values(#{userId},#{teamId},#{start},#{end},#{reservedNumber})")
    void insertResInf(@Param("start") java.sql.Timestamp start, @Param("end") java.sql.Timestamp end, @Param("teamId") int teamId, @Param("userId") int userId,@Param("reservedNumber") int reservedNumber);
// and DATE(reservationEndTime) = CURRENT_DATE()
//    @Select("select count(*) from usestadium where teamId = #{teamId} and userId = #{userId} and isDelete = 0 and DATE(reservationEndTime) = CURRENT_DATE() and TIME(reservationEndTime) > CURRENT_TIME() and isDelete = 0")
    @Select("SELECT COUNT(*) FROM usestadium \n" +
            "WHERE userId = #{userId} AND teamId = #{teamId} AND isDelete = 0 \n" +
            "      AND DATE(reservationEndTime) >= CURRENT_DATE() \n" +
            "      AND TIME(reservationEndTime) > CURRENT_TIME()")
    Integer isBooked(@Param("userId") Integer userId,@Param("teamId") Integer teamId);

    @Update("update usestadium set isDelete = 1 where userId = #{userId} and teamId = #{teamId} and DATE(reservationEndTime) = CURRENT_DATE()")
    void delete(@Param("userId") Integer userId,@Param("teamId") Integer teamId);

    @Select("select * from user where id = #{userId}")
    User getInf(Integer userId);

    @Update("UPDATE user SET userAccount = #{userAccount},gender = #{gender}, age = #{age}, phone = #{phone}, email = #{email} WHERE id = #{id}")
    void update(User user);
}
